// 状态： 红灯、绿灯、黄灯
class State {
    constructor(color) {
        this.color = color
    }
    handle(context) {
        console.log(`turn to ${this.color} light`)
        context.setState(this)
    }
}

class Context {
    constructor() {
        this.state = null
    }
    getState() {
        return this.state;
    }
    setState(state) {
        this.state = state;
    }
}

let context = new Context();

let red = new State('red');
red.handle(context);
console.log(context.getState())
let green = new State('green');
green.handle(context);
console.log(context.getState())
let yellow = new State('yello');
yellow.handle(context);
console.log(context.getState());